package edu.ucsc.mit2008.swan.editor.coreUI.internal.presentation.wizard.page;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;

import edu.ucsc.mit2008.swan.core.util.StringUtils;
import edu.ucsc.mit2008.swan.editor.core.presentation.model.IModelChangedListener;
import edu.ucsc.mit2008.swan.editor.core.presentation.model.ISwanPresentation;

public class NewPresentationWizardFirstPage extends WizardPage {

	private NewPresentationWizardFirstPageUI pageUI;

	private ISwanPresentation currentModel;
	
	private List<IModelChangedListener> listeners = new ArrayList<IModelChangedListener>();
	
	public NewPresentationWizardFirstPage() {
		super("newPresentation");
		setTitle("New Presentation");
		setDescription("Create a new Presentation");
	}

	@Override
	public void createControl(Composite parent) {
		pageUI = new NewPresentationWizardFirstPageUI(parent, SWT.NONE);
		setControl(pageUI);
		for(IModelChangedListener listener:listeners){
			pageUI.addModelChangedListener(listener);
		}
		pageUI.modelChanged(currentModel);
	}

	public void setModel(ISwanPresentation model){
		this.currentModel = model;
	}
	
	public void addModelChangedListener(IModelChangedListener listener){
		listeners.add(listener);
	}
	
	@Override
	public boolean isPageComplete() {
		setErrorMessage("");
		if(currentModel == null){
			setErrorMessage("Problem creating presentation.");
			return false;
		} else {
			if(StringUtils.isEmpty(currentModel.getName())){
				setErrorMessage("Presentation Name cannot be empty.");
				return false;
			}
		}
		return true;
	}
}
